import numpy as np

# 聚合运算(所有聚合运算都提供轴axis参数，默认为0轴)
L = np.random.random(100)
print(np.sum(L))
print(np.max(L))
print(np.min(L))

# 矩阵的聚合运算
X = np.arange(16).reshape(4, -1)
print(X)
# 求矩阵中所有元素的和
print(np.sum(X))
# 沿着0轴求每列的和
print(np.sum(X, axis=0))
# 沿着1轴求每列的和
print(np.sum(X, axis=1))

# 求所有元素的乘积
print(np.prod(X + 1))
# 求所有元素的均值
print(np.mean(X))
# 求所有元素的中位数
print(np.median(X))
# 求百分位点
print(np.percentile(X,50))
for percent in [0, 25, 50, 75, 100]:
    print(np.percentile(X, q=percent))

# 求方差
print("var:", np.var(X))
# 求标准差
print("std:", np.std(X))
